﻿using Siemens.Engineering.SW.Blocks;
using Siemens.Engineering.SW;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TIA_Openness
{
    public static class EnumerateAllBlock
    {
        //Enumerates all block user groups including sub groups
        public static List<PlcBlock> plcBlocks = new List<PlcBlock>();
        public static void EnumerateAllBlockGroupsAndSubgroups(PlcSoftware plcsoftware)
        {
            foreach (PlcBlockUserGroup blockUserGroup in plcsoftware.BlockGroup.Groups)
            {
                EnumerateBlockUserGroups(blockUserGroup);
            }
        }
        public static void EnumerateBlockUserGroups(PlcBlockUserGroup blockUserGroup)
        {
            foreach (PlcBlockUserGroup subBlockUserGroup in blockUserGroup.Groups)
            {
                EnumerateBlockUserGroups(subBlockUserGroup);
                // recursion
                //foreach (var item in subBlockUserGroup.Blocks)
                //{
                //    plcBlocks.Add(item);
                //}
            }
            foreach (var item in blockUserGroup.Blocks)
            {
                plcBlocks.Add(item);
            }
        }
    }
}
